package pri.zxx.webdemo.controllers;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pri.zxx.webdemo.config.properties.SwaggerProperties;
import pri.zxx.webdemo.entity.vo.ResultData;
import pri.zxx.webdemo.quartzdemo.utils.SpringUtils;
import pri.zxx.webdemo.utils.GsonUtil;
import pri.zxx.webdemo.utils.TimeUtils;
import pri.zxx.word.TestReporter;
import pri.zxx.word.WordBaseDataProperties;
import pri.zxx.word.dat.ExperimentResult;
import pri.zxx.word.dat.WordData;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Twilight
 * @desc
 * @createTime 2020-09-04-21:00
 */
@RestController
@Slf4j
@RequestMapping(value = "/test")
@Tag(name = "LEARN_DEMO-测试")
public class TestController {
	@Autowired
	private SwaggerProperties swaggerProperties;

	@Autowired
	private WordBaseDataProperties wordBaseDataProperties;

	@GetMapping("/test")

	public ResultData<String> myTest() {
		String s = GsonUtil.toJson(swaggerProperties);
		System.out.println(s);
		return ResultData.success(s);
	}

	@GetMapping("methodsTest")
	@Operation(summary = "方法调用链条测试")
	public void methodTest() {
		TestController bean = SpringUtils.getBean(TestController.class);
		bean.methodA();
		for (int i = 0; i < 3; i++) {
			bean.methodB();
		}
	}

	public void methodB() {
		TimeUtils.pause(0, 0, 100);
	}

	public void methodA() {
		TimeUtils.pause(0, 0, 300);
	}

	@GetMapping("word")
	@Operation(summary = "word")
	public void word() {
		WordData wordData = new WordData();
		wordData.setWordBaseDataProperties(wordBaseDataProperties);
		List<WordData.GroupInfo> groupInfos = new ArrayList<>();
		groupInfos.add(new WordData.GroupInfo().setGroupName("T1").setDesc("分组1").setOrder(1).setGroupId(1L));
		groupInfos.add(new WordData.GroupInfo().setGroupName("T2").setDesc("分组2").setOrder(2).setGroupId(2L));
		groupInfos.add(new WordData.GroupInfo().setGroupName("T3").setDesc("分组3").setOrder(3).setGroupId(3L));
		groupInfos.add(new WordData.GroupInfo().setGroupName("T4").setDesc("分组4").setOrder(4).setGroupId(4L));
		groupInfos.add(new WordData.GroupInfo().setGroupName("T5").setDesc("分组5").setOrder(4).setGroupId(5L));
		groupInfos.add(new WordData.GroupInfo().setGroupName("T6").setDesc("分组6").setOrder(4).setGroupId(6L));
		groupInfos.add(new WordData.GroupInfo().setGroupName("T7").setDesc("分组7").setOrder(4).setGroupId(7L));
		wordData.setGroupInfos(groupInfos);

		List<WordData.StageInfo> stageInfoList = new ArrayList<>();


		List<WordData.SimpleTableInfo> rawInfo = new ArrayList<>();
		rawInfo.add(new WordData.SimpleTableInfo().setName("原料1").setValue(BigDecimal.valueOf(100))
				.setStageId(1L).setGroupId(1L));
		rawInfo.add(new WordData.SimpleTableInfo().setName("原料1").setValue(BigDecimal.valueOf(99))
				.setStageId(1L).setGroupId(2L));
		rawInfo.add(new WordData.SimpleTableInfo().setName("原料2").setValue(BigDecimal.valueOf(19))
				.setStageId(1L).setGroupId(1L));
		rawInfo.add(new WordData.SimpleTableInfo().setName("原料2").setValue(BigDecimal.valueOf(18))
				.setStageId(1L).setGroupId(3L));


		List<WordData.SimpleTableInfo> nutritionInfo = new ArrayList<>();
		nutritionInfo.add(new WordData.SimpleTableInfo().setGroupId(1l).setStageId(1L).setName("营养指标1")
				.setValue(BigDecimal.valueOf(11)));
		nutritionInfo.add(new WordData.SimpleTableInfo().setGroupId(2l).setStageId(1L).setName("营养指标1")
				.setValue(BigDecimal.valueOf(2)));
		stageInfoList.add(new WordData.StageInfo().setStageName("阶段1（0d-14d）").setDesc("阶段1")
				.setStartDays(0).setEndDays(14).setRawInfos(rawInfo).setNutritionInfo(nutritionInfo));

		stageInfoList.add(new WordData.StageInfo().setStageName("阶段2（15d-30d）").setDesc("阶段1")
				.setStartDays(15).setEndDays(30).setRawInfos(rawInfo).setNutritionInfo(nutritionInfo));
		wordData.setStageInfoList(stageInfoList);

		List<ExperimentResult> resultList = new ArrayList<>();

		resultList.add(new ExperimentResult().setExpId(1L)
				.setExpTypeName("蛋白质")
				.setGroupName("T1")
				.setIndicator("指标1")
				.setValue(BigDecimal.valueOf(10))
				.setVariance(new BigDecimal("1.133"))
				.setSubscript("b"));
		resultList.add(new ExperimentResult().setExpId(1L)
				.setExpTypeName("蛋白质")
				.setGroupName("T2")
				.setIndicator("指标1")
				.setValue(BigDecimal.valueOf(20))
				.setVariance(new BigDecimal("2.133"))
				.setSubscript("a"));
		resultList.add(new ExperimentResult().setExpId(1L)
				.setExpTypeName("蛋白质")
				.setGroupName("T3")
				.setIndicator("指标1")
				.setValue(BigDecimal.valueOf(30))
				.setVariance(new BigDecimal("3.133"))
				.setSubscript("c"));
		resultList.add(new ExperimentResult().setExpId(1L)
				.setExpTypeName("蛋白质")
				.setGroupName("T4")
				.setIndicator("指标1")
				.setValue(BigDecimal.valueOf(40))
				.setVariance(new BigDecimal("4.1332313131313"))
				.setSubscript("d"));

		resultList.add(new ExperimentResult().setExpId(1L)
				.setExpTypeName("蛋白质")
				.setGroupName("T1")
				.setIndicator("指标2")
				.setValue(BigDecimal.valueOf(40))
				.setVariance(new BigDecimal("11.1332313131313"))
				.setSubscript("a"));

		resultList.add(new ExperimentResult().setExpId(1L)
				.setExpTypeName("蛋白质")
				.setGroupName("T2")
				.setIndicator("指标2")
				.setValue(BigDecimal.valueOf(40))
				.setVariance(new BigDecimal("12.1332313131313"))
				.setSubscript("b"));

		resultList.add(new ExperimentResult().setExpId(1L)
				.setExpTypeName("蛋白质")
				.setGroupName("T3")
				.setIndicator("指标2")
				.setValue(BigDecimal.valueOf(40))
				.setVariance(new BigDecimal("32.1332313131313"))
				.setSubscript("c"));


		resultList.add(new ExperimentResult().setExpId(1L)
				.setStageName("阶段1（0d-14d）")
				.setExpTypeName("蛋品质")
				.setGroupName("T1")
				.setIndicator("ADG（g/d）")
				.setValue(BigDecimal.valueOf(10))
				.setVariance(new BigDecimal("1.133"))
				.setSubscript("b"));
		resultList.add(new ExperimentResult().setExpId(1L)
				.setExpTypeName("蛋品质")
				.setStageName("阶段1（0d-14d）")
				.setGroupName("T2")
				.setIndicator("ADG（g/d）")
				.setValue(BigDecimal.valueOf(20))
				.setVariance(new BigDecimal("2.133"))
				.setSubscript("a"));
		resultList.add(new ExperimentResult().setExpId(1L)
				.setStageName("阶段2（15d-30d）")
				.setExpTypeName("蛋品质")
				.setGroupName("T3")
				.setIndicator("ADFI（g/d）")
				.setValue(BigDecimal.valueOf(30))
				.setVariance(new BigDecimal("3.133"))
				.setSubscript("c"));
		resultList.add(new ExperimentResult().setExpId(1L)
				.setStageName("阶段2（15d-30d）")
				.setExpTypeName("蛋品质")
				.setGroupName("T4")
				.setIndicator("ADFI（g/d）")
				.setValue(BigDecimal.valueOf(40))
				.setVariance(new BigDecimal("4.1332313131313"))
				.setSubscript("d"));
		resultList.add(new ExperimentResult().setExpId(1L)
				.setStageName("阶段2（15d-30d）")
				.setExpTypeName("蛋品质")
				.setGroupName("T5")
				.setIndicator("ADFI（g/d）")
				.setValue(BigDecimal.valueOf(40))
				.setVariance(new BigDecimal("5.133"))
				.setSubscript("f"));

		resultList.add(new ExperimentResult().setExpId(1L)
				.setStageName("阶段2（15d-30d）")
				.setExpTypeName("蛋品质")
				.setGroupName("P")
				.setIndicator("ADFI（g/d）")
				.setValue(BigDecimal.valueOf(40))
				.setVariance(new BigDecimal("4.133"))
				.setSubscript("d"));
		resultList.add(new ExperimentResult().setExpId(1L)
				.setStageName("阶段2（15d-30d）")
				.setExpTypeName("蛋品质")
				.setGroupName("CV%")
				.setIndicator("ADFI（g/d）")
				.setValue(BigDecimal.valueOf(22))
				.setVariance(new BigDecimal("23.133"))
				.setSubscript("d"));

		wordData.setExperimentResults(resultList);

		new TestReporter().customStyle(wordData).headerFooter(wordData).buildContext(wordData).out("test.docx");
	}


}
